/**
 * 
 */
package org.vectrics.recruiter.struts.admin.person;

import java.util.List;

import javax.servlet.jsp.JspException;

import org.apache.struts.action.ActionMessages;
import org.vectrics.cv.Career;
import org.vectrics.cv.Language;
import org.vectrics.cv.PersonLanguage;
import org.vectrics.cv.Studies;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.job.JobFunction;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;
import org.vectrics.user.Person;

/**
 * @author pgoette
 * Action encargado de borrar un Lenguage
 */
public class DeleteLanguageAction extends VectricsStrutsAction {


	@Override
	protected String doExecute(VectricsActionData actionData)
			throws JspException {
		
		String forward = "success";
		String idLanguage = actionData.getRequest().getParameter("languageId");
        CareerForm form = (CareerForm) actionData.getForm();
		
        if ((idLanguage!=null) && (!idLanguage.trim().equals(""))) {
        	// Busco la Lenguaje segun el id.
        	Language language = RecruitServiceLocator.getPersonService().findLanguageById(new Long(idLanguage));
			// Recupero todas las personas
        	List<PersonLanguage> personLanguages = RecruitServiceLocator.getPersonService().findAllPersonLanguage(new Long(idLanguage));
			
        	if ((personLanguages==null)||(personLanguages.isEmpty())) {
        		RecruitServiceLocator.getPersonService().deleteLanguage(language);        		
        	} else {
        		actionData.addError(ActionMessages.GLOBAL_MESSAGE, "error.delete.person.language"); 
        	}
		} 
		
		return forward;
	}

}
